from flask import Flask, render_template, request, redirect,Response
import requests

app = Flask(__name__)

students=[]

# Login route
# @app.route('/', methods=['GET', 'POST'])
# def login():
#     if request.method == 'POST':
#         username = request.form['username']
#         password = request.form['password']
        
#         # Here you can add your authentication logic
#         # For simplicity, let's just check if the username and password are not empty
#         if username=="admin" and password=="123":
#             return "登录成功, " + username
#         else:
#             return "登录失败"
    
#     return render_template('local.html')
@app.route('/store')
def store():
    return render_template('ajax.html')

@app.route('/effect')
def effect():
    return render_template('jqueryEffect.html')


@app.route("/addStudent",methods=['post'])#获取学生信息页面\
def addStudent():
    # data=request.data
    # students.append(data)
    # print(students)
    return 'ok 我收到你发给我的学生数据了'

@app.route('/getStudent',methods=['get'])
def getStudent():
    return json.dumps(students)

@app.route('/query')
def getQuery():
    return render_template('jqueryStudy.html')


@app.route('/jquery') # 获取学生信息页面
def jquery():
    return render_template('jquery.html')

@app.route('/proxy')
def proxy():
    # Get the URL to proxy from the query parameters
    proxy_url = request.args.get('url')

    if not proxy_url:
        return Response('Missing URL parameter', status=400)

    try:
        # Make a request to the provided URL
        response = requests.get(proxy_url)

        # Return the response from the proxied URL
        return Response(response.content, content_type=response.headers['Content-Type'])

    except Exception as e:
        return Response(str(e), status=500)


if __name__ == '__main__':
    app.run(debug=True,host='0.0.0.0',port=8089)
